package com.yanqu.road.server.logic.task.condition;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.TaskConditionInfo;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.task.BaseCondition;
import com.yanqu.road.server.logic.task.BaseTaskData;

import java.math.BigInteger;

/**
 * @author ：zfr
 * @date ：2021/6/28 16:37
 */
public class CatchThiefCountCondition extends BaseCondition {

    public CatchThiefCountCondition(TaskConditionInfo taskConditionInfo, BaseTaskData baseTaskData, BigInteger value, Object initArgs) {
        super(taskConditionInfo, baseTaskData, value, initArgs);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.CatchThiefCount.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.CatchThiefCount.getValue(), handle);
    }

    public boolean isCompleted(GamePlayer player) {
        BigInteger param4 = taskConditionInfo.getParamList().get(3);
        return getValue().compareTo(param4) >= 0;
    }

    @Override
    protected void changeValue(Object object) {
        long times = (long) object;
        if(times > 0) {
            setValue(BigInteger.valueOf(times));
        }
    }
}
